package com.gxc.config;

import com.gxc.filter.MyFilter;
import com.gxc.interceptors.RequestInterceptor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * WebMvcConfigBean.
 *
 * @author 宫新程
 * @since 2018/12/29 1:33 PM
 */
@Configuration
public class WebMvcConfigBean implements WebMvcConfigurer {

  /** 配置拦截器. */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry
        .addInterceptor(new RequestInterceptor())
        .addPathPatterns("/**")
        .excludePathPatterns("/login");
  }

  /** 配置过滤器. */
  @Bean
  public FilterRegistrationBean<MyFilter> filterRegistrationBean() {
    FilterRegistrationBean<MyFilter> result = new FilterRegistrationBean<>();
    result.addUrlPatterns("/*");
    result.setFilter(new MyFilter());
    return result;
  }
}
